package com.harassment.interception.ui.fragments.bottomFragment;

import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;

import com.harassment.interception.R;
import com.harassment.interception.ui.fragments.HIFragmentManager;
import com.harassment.interception.ui.fragments.interceptRecord.InterceptRecordFragment;
import com.harassment.interception.ui.fragments.listManagement.ListManagementFragment;
import com.harassment.interception.ui.fragments.setting.SettingFragment;

public class BottomBar implements BottomNavigationView.OnNavigationItemSelectedListener{
    private static final String TAG = "BottomBar";
    private HIFragmentManager mHIFragmentManager;
    private int mContentBox = R.id.content_box;
    private int mBottomContentBox = R.id.bottom_navigation_box;

    private InterceptRecordFragment mIRFragment;
    private ListManagementFragment mLMFragment;
    private SettingFragment mSettingFragment;

    private BottomNavigationView mBottomNavigationView;
    private LinearLayout mOperateView;

    public BottomBar(AppCompatActivity appCompatActivity) {
        mHIFragmentManager = new HIFragmentManager(appCompatActivity);

        mIRFragment = new InterceptRecordFragment();
        mLMFragment = new ListManagementFragment();
        mSettingFragment = new SettingFragment();
        mHIFragmentManager.showFragment(mContentBox, mIRFragment);

        mBottomNavigationView = appCompatActivity.findViewById(R.id.bottom_navigation);
        mBottomNavigationView.setOnNavigationItemSelectedListener(this);

        mOperateView = appCompatActivity.findViewById(R.id.select_box);
    }

    public HIFragmentManager getHIFragmentManager() {
        return mHIFragmentManager;
    }

    public void showOperateView(){
        mBottomNavigationView.setVisibility(View.GONE);
        mOperateView.setVisibility(View.VISIBLE);
    }

    public void showBottomNavigationView(){
        mBottomNavigationView.setVisibility(View.VISIBLE);
        mOperateView.setVisibility(View.GONE);
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.intercept_record:
                mHIFragmentManager.showFragment(mContentBox, mIRFragment);
                break;
            case R.id.list_management:
                mHIFragmentManager.showFragment(mContentBox, mLMFragment);
                break;
            case R.id.setting:
                mHIFragmentManager.showFragment(mContentBox, mSettingFragment);
                break;
        }
        return true;
    }

    public InterceptRecordFragment getIRFragment() {
        return mIRFragment;
    }

    public ListManagementFragment getLMFragment() {
        return mLMFragment;
    }

    public SettingFragment getSettingFragment() {
        return mSettingFragment;
    }

    public BottomNavigationView getBottomNavigationView() {
        return mBottomNavigationView;
    }

    public LinearLayout getOperateView() {
        return mOperateView;
    }
}
